package com.itcast.peft.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.itcast.peft.service.QuestionService;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/generateQuestion")
    @ResponseBody
    public String generateQuestion() {
        questionService.generateQuestion();
        return "success";
    }
    
    @PostMapping("/toVolcesBatchformat")
    @ResponseBody
    public ResponseEntity<byte[]> toVolcesBatchformat() throws IOException {
        // 输出数据为下载文件的形式
        return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
                .header("Content-disposition", "attachment; filename=data_question_volcesbatch.jsonl")
                .body(questionService.toVolcesBatchformat());
    }
    
}
